package me.jiatao.jetpack;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import me.jiatao.jetpack.lifecycle.BasePresenter;
import me.jiatao.jetpack.lifecycle.DefaultPresenter;
import me.jiatao.jetpack.lifecycle.IDefaultPresenter;
import me.jiatao.jetpack.lifecycle.IPresenter;

public class LifecycleActivity extends AppCompatActivity {
    private static final String TAG = "***LifecycleActivity***";
    private IPresenter presenter;
    private IDefaultPresenter defaultPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i(TAG, "LifecycleActivity--->onCreate");

        //项目中会实例化BasePresenter子类
        //这里仅适用于测试

        //两种方式使用Lifecycle
        //一种是使用注解方式
        presenter = new BasePresenter();
        getLifecycle().addObserver(presenter);

        //第二种是实现DefaultLifecycleObserver接口
        //推荐是第二种方式
        defaultPresenter = new DefaultPresenter();
        getLifecycle().addObserver(defaultPresenter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        Log.i(TAG, "LifecycleActivity--->onDestroy");
    }
}
